package com.example.wacai.ceshi;

import com.example.wacai.ceshi.model.AccountingRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@RestController
public class AccountingController {

    List<AccountingRecord> Records = new ArrayList<>();

    String str;
    @RequestMapping("/record")
    public String record(AccountingRecord accountingRecord)
    {
        Date date = new Date();
        accountingRecord.setTime(date);
        Records.add(accountingRecord);



        str = str+"类型："+accountingRecord.getType()+"金额："+accountingRecord.getAmount()+"创建时间"+
                        accountingRecord.getCreateTime()+"活动："+accountingRecord.getCategory()+"\r\n";







        return str;
    }

    @RequestMapping("/search")
    public String search(@RequestParam("amount") int amount)
    {
            List<AccountingRecord> accountingRecordList=Records;
            accountingRecordList.stream().filter(st->st.getAmount()>amount);

            StringBuilder stringBuilder = new StringBuilder();

        for (AccountingRecord accountingRecord:accountingRecordList
             ) {
            stringBuilder.append("类型："+accountingRecord.getType()+"金额："+accountingRecord.getAmount()+"创建时间"+
                    accountingRecord.getCreateTime()+"活动："+accountingRecord.getCategory());


        }
            return stringBuilder.toString();

    }
}
